package Leetcode第一期;

public class 二叉搜索树的第k大节点_54 {
    int k,res;
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }


    public int kthLargest(TreeNode root,int k) {
        this.k=k;
       dfs(root);
       return res;
    }

    private void dfs(TreeNode root) {
        if (root==null)return;
        if(k==0)return;
        dfs(root.right);
        k--;
        if(k==0) this.res=root.val;
        dfs(root.left);
    }

}

